/**
 * 
 */
package persistency;

/**
 * @author Johan *
 * @author Veronique
 * @author Pierre
 * 
 * @version 20111109
 *
 */
import java.io.File;
import java.io.FileNotFoundException;
//import java.lang.IllegalStateException;
import java.util.NoSuchElementException;
import java.util.Scanner;


public class DataLezer implements ILeesbaar{
	private Scanner input = null;
	
	public DataLezer ()
	{
		//lege default constructor
	}
		
	public Scanner openFile (String bestand)
	{
	     //File dir1 = new File (".");
	     //File dir2 = new File ("..");
		try 
		{
		   //    System.out.println ("Current dir : " + dir1.getCanonicalPath());
		   //    System.out.println ("Parent  dir : " + dir2.getCanonicalPath());
		   input = new Scanner( new File(bestand));
			input.useDelimiter(System.getProperty("line.separator"));	
		} catch (FileNotFoundException e) 
		{
			System.err.printf("Kan bestand %s niet openen\n",bestand);
			System.err.println(e);
			//System.exit (1);
		}
		catch (Exception e) {
			e.printStackTrace();
		}
		return input;
	}
	
	public String leesLijn(Scanner input) 
	{
		String deLijn = null;
		try
		{
				deLijn = input.next(); 
		} 
		catch (NoSuchElementException e)
		{
			System.err.println(e);
		}
		catch (Exception e)
		{
			System.err.println(e);
		}
		return deLijn;
	}
	
	public void closeFile(Scanner input)
	{
		if (input != null)
				input.close();//Close File if open
	}
}
